<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item label="主键" prop="id">
        <el-input v-model="dataForm.id" placeholder="主键"></el-input>
      </el-form-item>
      <el-form-item label="订单id" prop="orderId">
        <el-input v-model="dataForm.orderId" placeholder="订单id"></el-input>
      </el-form-item>
      <el-form-item label="会员id" prop="accountId">
        <el-input v-model="dataForm.accountId" placeholder="会员id"></el-input>
      </el-form-item>
      <el-form-item label="展会id" prop="exhId">
        <el-input v-model="dataForm.exhId" placeholder="展会id"></el-input>
      </el-form-item>
      <el-form-item label="展会名称" prop="exhName">
        <el-input v-model="dataForm.exhName" placeholder="展会名称"></el-input>
      </el-form-item>
      <el-form-item label="类型：1展位、2主场服务、3论坛、4酒店" prop="type">
        <el-input v-model="dataForm.type" placeholder="类型：1展位、2主场服务、3论坛、4酒店"></el-input>
      </el-form-item>
      <el-form-item label="与type对应" prop="itemId">
        <el-input v-model="dataForm.itemId" placeholder="与type对应"></el-input>
      </el-form-item>
      <el-form-item label="项目内容" prop="itemContent">
        <el-input v-model="dataForm.itemContent" placeholder="项目内容"></el-input>
      </el-form-item>
      <el-form-item label="数量" prop="number">
        <el-input v-model="dataForm.number" placeholder="数量"></el-input>
      </el-form-item>
      <el-form-item label="项目单价" prop="price">
        <el-input v-model="dataForm.price" placeholder="项目单价"></el-input>
      </el-form-item>
      <el-form-item label="押金" prop="deposit">
        <el-input v-model="dataForm.deposit" placeholder="押金"></el-input>
      </el-form-item>
      <el-form-item label="项目总价" prop="totalPrice">
        <el-input v-model="dataForm.totalPrice" placeholder="项目总价"></el-input>
      </el-form-item>
      <el-form-item label="押金总价" prop="totalDeposit">
        <el-input v-model="dataForm.totalDeposit" placeholder="押金总价"></el-input>
      </el-form-item>
      <el-form-item label="支付总价" prop="totalAmount">
        <el-input v-model="dataForm.totalAmount" placeholder="支付总价"></el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";
import baseService from "@/service/baseService";
import { useDebounce } from "@/utils/utils";
export default defineComponent({
  setup() {
    return reactive({
      visible: false,
      dataForm: {
        id: "",
        orderId: "",
        accountId: "",
        exhId: "",
        exhName: "",
        type: "",
        itemId: "",
        itemContent: "",
        number: "",
        price: "",
        deposit: "",
        totalPrice: "",
        totalDeposit: "",
        totalAmount: ""
      }
    });
  },
  computed: {
    dataRule() {
      return {};
    }
  },
  created() {
    this.dataFormSubmitHandle = useDebounce(this.dataFormSubmitHandle);
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataFormRef"].resetFields();
        if (this.dataForm.id) {
          this.getInfo();
        }
      });
    },
    // 获取信息
    getInfo() {
      baseService.get("/noc/torderitem/" + this.dataForm.id).then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.dataForm = res.data;
      });
    },
    // 表单提交
    dataFormSubmitHandle() {
      this.$refs["dataFormRef"].validate((valid: boolean) => {
        if (!valid) {
          return false;
        }
        (!this.dataForm.id ? baseService.post : baseService.put)("/noc/torderitem", this.dataForm).then((res) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        });
      });
    }
  }
});
</script>
